package com.exprecards.common.web;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import com.exprecards.common.persistence.DAOFactory;
import com.exprecards.common.persistence.dto.ExpTbEmpresa;
import com.exprecards.common.persistence.dto.ExpTbEmpresaPk;
import com.exprecards.common.persistence.exceptions.ExpTbEmpresaDaoException;

@ManagedBean(name = "gestionPresupuestoBean")
@SessionScoped
public class GestionPresupuestoBean  implements Serializable{

	private static final long serialVersionUID = 1L;

	@ManagedProperty(value = "#{userSessionBean}")
	private UserSessionBean userSessionBean;

	
	public GestionPresupuestoBean(){
		
		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
		userSessionBean = (UserSessionBean)session.getAttribute("userSessionBean");
	}
	
	
	public void guardarEmpresa(){
		
		ExpTbEmpresa emp = userSessionBean.getEmpresa();
		
		try {
			DAOFactory.getExpTbEmpresaDao().update( new ExpTbEmpresaPk( emp.getId()), emp);
			userSessionBean.setPresupuestoDisponible(emp.getPresupuestoInicial());
		} catch (ExpTbEmpresaDaoException e) {
			e.printStackTrace();
		}
	}
	
	public void limpiarEmpresa(){
		
		
	}
	
	public UserSessionBean getUserSessionBean() {
		return userSessionBean;
	}

	public void setUserSessionBean(UserSessionBean userSessionBean) {
		this.userSessionBean = userSessionBean;
	}
	
	
	 
}
